home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "List"
- Option Explicit
-
- Public g_vsfList As VSFlexData
- ' A global VSFlexData object that will serve
- ' as the doubly linked list
-
- Public Sub InsertNode(Data As VSFlexData)
- ' Inserts a node in the list
-
- Dim vsfTemp As VSFlexData
- Set vsfTemp = New VSFlexData
-
- With vsfTemp
- .SetMap
-
- If g_vsfList.Length > 0 Then
- Set !Prev = g_vsfList(g_vsfList.Length)
- Else
- Set !Prev = Nothing
- End If
-
- Set !Next = Nothing
- Set !Data = Data.Clone
- End With
-
- g_vsfList.AddLast vsfTemp
-
- If g_vsfList.Length > 1 Then
- g_vsfList(g_vsfList.Length - 1)!Next = g_vsfList(g_vsfList.Length)
- End If
- End Sub
-
- Public Function DeleteNode(Pos As Long)
- ' Deletes a node at a given position
-
- If g_vsfList(Pos) Is LastNode Then
- ' Last
- Set g_vsfList(Pos)!Prev!Next = Nothing
- ElseIf g_vsfList(Pos) Is FirstNode Then
- ' First
- Set g_vsfList(Pos)!Next!Prev = Nothing
- Else
- ' Middle
- Set g_vsfList(Pos)!Prev!Next = g_vsfList(Pos)!Next
- Set g_vsfList(Pos)!Next!Prev = g_vsfList(Pos)!Prev
- End If
-
- g_vsfList.Remove Pos
- End Function
-
- Public Property Get FirstNode() As VSFlexData
- ' Returns the first node
-
- If g_vsfList.Length Then
- Set FirstNode = g_vsfList(1)
- Else
- Set FirstNode = Nothing
- End If
- End Property
-
- Public Property Get LastNode() As VSFlexData
- ' Returns the last node
-
- If g_vsfList.Length Then
- Set LastNode = g_vsfList(g_vsfList.Length)
- Else
- Set LastNode = Nothing
- End If
- End Property
-
- Public Sub TraversePrint()
- ' Traverses the list and prints the result in
- ' the immediate/debug window
-
- Dim vsfTraverse As VSFlexData
- Dim vsfKeys As VSFlexData
- Dim lngCounter As Long
-
- Set vsfTraverse = FirstNode
-
- Do
- Set vsfKeys = vsfTraverse!Data.GetKeys
- For lngCounter = 1 To vsfKeys.Length
- Debug.Print vsfKeys(lngCounter) & "=" & vsfTraverse!Data(vsfKeys(lngCounter))
- Next lngCounter
-
- Set vsfTraverse = vsfTraverse!Next
- Debug.Print
- Loop While Not vsfTraverse Is Nothing
-
- Debug.Print
-
- End Sub
-
-
-